<template>
  <el-form :model="formData" label-width="120px" ref="form" v-loading="loading" class="pr-4">
    <el-form-item label="姓名" prop="user_name">
  <el-input v-model="formData.user_name" name="user_name" clearable />
</el-form-item>

<el-form-item label="头像" prop="head_img">
    <Upload v-model="formData.head_img" />
</el-form-item>

<el-form-item label="openid" prop="openid">
  <el-input v-model="formData.openid" name="openid" clearable />
</el-form-item>

<el-form-item label="unionid" prop="unionid">
  <el-input v-model="formData.unionid" name="unionid" clearable />
</el-form-item>

<el-form-item label="手机号" prop="phone">
  <el-input v-model="formData.phone" name="phone" clearable />
</el-form-item>

<el-form-item label="性别 1 男， 2 女" prop="sex">
  <el-radio-group v-model="formData.sex">
    <el-radio v-for="item in options" :key="item.value" :label="item.value" name="sex">{{ item.label }}</el-radio>
  </el-radio-group>
</el-form-item>

<el-form-item label="国家" prop="country">
  <el-input v-model="formData.country" name="country" clearable />
</el-form-item>

<el-form-item label="省份" prop="province">
  <el-input v-model="formData.province" name="province" clearable />
</el-form-item>

<el-form-item label="城市" prop="city">
  <el-input v-model="formData.city" name="city" clearable />
</el-form-item>

<el-form-item label="所在地区" prop="location">
  <el-input v-model="formData.location" name="location" clearable />
</el-form-item>

<el-form-item label="注册ip" prop="register_ip">
  <el-input v-model="formData.register_ip" name="register_ip" clearable />
</el-form-item>

<el-form-item label="注册时间" prop="register_date">
  <el-date-picker
      v-model="formData.register_date"
      type="datetime"
      name="register_date"
      placeholder="Pick a day"
      clearable
  />
</el-form-item>

<el-form-item label="用户状态 1 正常，2禁用" prop="status">
  <el-radio-group v-model="formData.status">
    <el-radio v-for="item in options" :key="item.value" :label="item.value" name="status">{{ item.label }}</el-radio>
  </el-radio-group>
</el-form-item>
    <div class="flex justify-end">
      <el-button type="primary" @click="submitForm(form)">{{ $t('system.confirm') }}</el-button>
    </div>
  </el-form>
</template>

<script lang="ts" setup>
import { useCreate } from '@/composables/curd/useCreate'
import { useShow } from '@/composables/curd/useShow'
import { onMounted } from 'vue'

const props = defineProps({
  primary: [String, Number],
  api: String,
})

const { formData, form, loading, submitForm, close } = useCreate(props.api as string, props.primary)

if (props.primary) {
  useShow(props.api as string, props.primary, formData)
}

const emit = defineEmits(['close'])
onMounted(() => {
  close(() => emit('close'))
})
</script>
